import Vue from 'vue'
import Vuex from 'vuex'
//import VueRouter from 'vue-router'
import getters from './getters'
import app from './modules/app'
import settings from './modules/settings'
import tagsView from './modules/tagsView'
import user from './modules/user'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    // 存储token
    // Authorization: sessionStorage.getItem('Authorization') ? sessionStorage.getItem('Authorization') : '',
    //console.log()
  },

  mutations: {
    // 修改token，并将token存入sessionStorage
    changeLogin (state, user) {
      // state.Authorization = user.Authorization;
      // sessionStorage.setItem('Authorization', user.Authorization);
    }
  },
  modules: {
    app,
    settings,
    user,
    tagsView
  },
  getters
})

// Vuex.beforeEach((to, from, next) => {
//   console.log('aaaaaaaaaaaa');
//   // to 将要访问的路径
//   // from 代表从哪个路径跳转而来
//   // next 是一个函数，表示放行
//   // next() 放行   next('/login') 强制跳转
//   if (to.path === '/login') return next()
//   // 获取token
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (!tokenStr) return next('/login')
//   next()

// })


export default store
